<?php
declare (strict_types = 1);

namespace app\api\controller\auth;

use app\api\controller\Api;
use app\common\system\logic\AuthNodeLogic;
use app\common\system\logic\UserRoleLogic;

class Menu extends Api
{
    public function index()
    {
        $user = $this->request->user;
        if ($user['id'] == 1) {
            $nodeLogic = new AuthNodeLogic();
            $list = $nodeLogic->getMenuItems();
        } else {
            $userRoleLogic = new UserRoleLogic();
            $list = $userRoleLogic->getMenuItems($user['id']);
        }
        $routes = build_menu([], $list, 0);
        $result = $routes;
        return success($result, '获取菜单成功');
    }
}
